<template>
  <div class="category">
    <b-scroll class="category-title">
      <category-list
        :category-list="categoryList"
        @categoryListItemClick="categoryListItemClick"
      />
    </b-scroll>
    <b-scroll class="subCategory">
      <sub-category-list :sub-category-list="subCategoryList" />
    </b-scroll>
  </div>
</template>

<script>
//网络
import { getCategory, getSubCategory } from "@/network/category";
//公共
import BScroll from "@/components/common/bscroll/BScroll";
//子
import CategoryList from "@/views/category/childComps/CategoryList";
import SubCategoryList from "@/views/category/childComps/SubCategoryList";
export default {
  name: "Category",
  components: {
    BScroll,
    CategoryList,
    SubCategoryList,
  },
  data() {
    return {
      categoryList: [],
      subCategoryList: [],
    };
  },
  created() {
    getCategory().then((res) => {
      let data = res.data;
      this.categoryList = data.category.list;
      getSubCategory(data.category.list[0].maitKey).then((res) => {
        let data = res.data;
        this.subCategoryList = data.list;
      });
    });
  },
  methods: {
    categoryListItemClick(maitKey) {
      getSubCategory(maitKey).then((res) => {
        this.subCategoryList = res.data.list;
      });
    },
  },
};
</script>

<style scoped>
.category {
  display: flex;
  height: 100vh;
}
.category-title {
  height: calc(100% - 48px);
  flex: 2;
  overflow: hidden;
  background-color: #f3f1f1;
}
.subCategory {
  flex: 5;
  height: calc(100% - 48px);
  overflow: hidden;
}
</style>
